package com.laizhenghua.wxstub.constant;

import com.laizhenghua.wxstub.interceptor.LoginInterceptor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @description:
 * @author: laizhenghua
 * @date: 2022/8/30 22:47
 */
@Component
public class AppConstant implements InitializingBean {
    private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoginInterceptor.class);

    @Value("${wx.base.url}")
    private String wxBaseURL;
    @Value("${wx.app.id}")
    private String wxAppId;
    @Value("${wx.app.secret}")
    private String wxAppSecret;

    @Value("${tq.app.id}")
    private String tqAppId;
    @Value("${tq.app.secret}")
    private String tqAppSecret;
    @Value("${tq.app.api.url}")
    private String tqAppApiUrl;

    @Value("${al.api.token}")
    private String alApiToken;
    @Value("${al.api.qh.url}")
    private String alApiQhUrl;
    @Value("${al.api.yq.url}")
    private String alApiYqUrl;
    @Value("${al.api.comment.url}")
    private String alApiCommentUrl;

    @Value("${coder.util.base.url}")
    private String coderUtilBaseUrl;
    @Value("${coder.util.access.key}")
    private String coderUtilAccessKey;
    @Value("${coder.util.secret.key}")
    private String coderUtilSecretKey;
    @Value("${filter.access.patterns}")
    private String patterns;
    @Value("${app.jwt.key}")
    private String appJwtKey;

    public static String WX_BASE_URL;
    public static String WX_TEMPLATE_ID;
    public static String WX_APP_ID;
    public static String WX_APP_SECRET;
    public static String TQ_APP_ID;
    public static String TQ_APP_SECRET;
    public static String TQ_APP_API_URL;
    public static String AL_API_TOKEN;
    public static String AL_API_QH_URL;
    public static String AL_API_YQ_URL;
    public static String CODER_UTIL_BASE_URL;
    public static String CODER_UTIL_ACCESS_KEY;
    public static String CODER_UTIL_SECRET_KEY;
    public static String AL_API_COMMENT_URL;
    public static String LOGIN_TOKEN_CACHE_NAME; // token缓存组件名称
    public static String[] FILTER_ACCESS_PATTERNS; // 取消拦截路径
    public static String APP_JWT_KEY;


    @Override
    public void afterPropertiesSet() throws Exception {
        WX_BASE_URL = wxBaseURL;
        WX_APP_ID = wxAppId;
        WX_APP_SECRET = wxAppSecret;
        TQ_APP_ID = tqAppId;
        TQ_APP_SECRET = tqAppSecret;
        TQ_APP_API_URL = tqAppApiUrl;
        AL_API_QH_URL = alApiQhUrl;
        AL_API_TOKEN = alApiToken;
        AL_API_YQ_URL = alApiYqUrl;
        CODER_UTIL_BASE_URL = coderUtilBaseUrl;
        CODER_UTIL_ACCESS_KEY = coderUtilAccessKey;
        CODER_UTIL_SECRET_KEY = coderUtilSecretKey;
        AL_API_COMMENT_URL = alApiCommentUrl;
        LOGIN_TOKEN_CACHE_NAME = "loginTokenCache";
        FILTER_ACCESS_PATTERNS = getExcludePath(patterns);
        APP_JWT_KEY = appJwtKey;
    }
    public static String[] getExcludePath(String patterns) {
        String[] patternArray = patterns.split(",");
        log.info("filter patterns " + Arrays.toString(patternArray));
        return patternArray;
    }
}
